//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.domain.ToolFile;
import com.ruoyi.system.domain.vo.FileVo;
import com.ruoyi.system.service.IToolFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(
        tags = {"工具基础操作加上传"}
)
@RestController
@RequestMapping({"/file"})
public class ToolFileController extends BaseController {
    @Autowired
    private IToolFileService toolfileService;
    @Autowired
    private TokenService tokenService;

    public ToolFileController() {
    }

    @ApiOperation("文件上传")
    @RequiresPermissions({"file:manage:add"})
    @PostMapping({"/uploadFiles"})
    public String uploadFiles(@RequestBody List<FileVo> fileVos) {
        return this.toolfileService.tOOLFileUpload(fileVos);
    }

    @ApiOperation("工具查询列表")
    @RequiresPermissions({"file:manage:list"})
    @PostMapping({"/list"})
    public TableDataInfo list(@RequestBody ToolFile file) {
        PageDomain pageDomain = new PageDomain();
        SysUser sysUser = this.tokenService.getLoginUser().getSysUser();
        if (StringUtils.isBlank(file.getOrgNo())) {
            file.setOrgNo(sysUser.getOrgNo());
        }

        BeanUtils.copyProperties(file, pageDomain);
        this.startPage(pageDomain);
        List<ToolFile> list = this.toolfileService.selectToolFileList(file);
        return this.getDataTable(list);
    }

    @ApiOperation("添加")
    @Log(
            title = "工具",
            businessType = BusinessType.INSERT
    )
    @PostMapping({"/add"})
    public AjaxResult add(@RequestBody FileVo file) {
        return this.toAjax(this.toolfileService.insertToolFile(file));
    }

    @ApiOperation("工具查询详情")
    @RequiresPermissions({"file:manage:query"})
    @GetMapping({"/info"})
    public AjaxResult getInfo(@RequestParam("fileId") String fileId) {
        return AjaxResult.success(this.toolfileService.selectToolFileByFileId(fileId));
    }

    @ApiOperation("修改")
    @RequiresPermissions({"file:manage:edit"})
    @Log(
            title = "工具",
            businessType = BusinessType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody ToolFile file) {
        return this.toAjax(this.toolfileService.updateToolFile(file));
    }

    @ApiOperation("删除")
    @RequiresPermissions({"file:manage:remove"})
    @Log(
            title = "工具",
            businessType = BusinessType.DELETE
    )
    @GetMapping({"/remove"})
    public AjaxResult remove(@RequestParam("ids") String ids) {
        return AjaxResult.success(this.toolfileService.deleteToolFileByIds(ids));
    }
}
